<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no, user-scalable=no">
		<script>
			var designW = 750,
				designH = 1346;
			var windowW = window.innerWidth,
				windowH = window.innerHeight;
			var scaleX = windowW / designW,
				scaleY = windowH / designH;
			var scale = Math.min(scaleX, scaleY);
			// var htmlEle = document.querySelector('html');
			// htmlEle.style.transform = 'scale(' + scale + ')';
			var metaTags = document.getElementsByTagName('meta');
			for (var i = 0; i < metaTags.length; i++) {
				// 判断当前元素是否为 viewport 相关的 meta 标签
				if (metaTags[i].getAttribute("name") === "viewport") {
					// 设置新的 initial-scale 值
					metaTags[i].setAttribute(
						"content",
						"width=device-width, shrink-to-fit=no, user-scalable=no, initial-scale=" + scale
					);
					break; // 只需修改第一个符合条件的 meta 标签，因此跳出循环
				}
			}
		</script>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="renderer" content="webkit">
		<title>联通大流量卡申领</title>
		<meta name="description" content="联通大流量卡申领" />
		<meta name="keywords" content="" />
		<link rel="stylesheet" type="text/css" href="/5G/city_picker_h5/css/jquery-weui.min.css" />
		<link href="/static/service/js/layui/css/layui.mobile.css" rel="stylesheet" />
		<style >
			body {
				margin: 0;
				background: #2AB2FE;
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.mainBox {
				width: 100%;
				max-width: 750px;
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.mainBox .topBox {
				width: 100%;
				position: relative;
			}

			.mainBox .topBox .topTxt {
				width: 60%;
				position: absolute;
				top: 16px;
				left: 20%;
				font-weight: 400;
				font-size: 24px;
				color: #FFFFFF;
				text-align: center;
			}

			.mainBox .addrBox {
				padding: 36px;
				width: calc(100% - 72px);
				background: #FFFFFF;
				border-radius: 24px;
				display: flex;
				flex-direction: column;
			}

			.mainBox .addrBox .addrTitle {
				margin-bottom: 20px;
				width: 100%;
				font-weight: 500;
				font-size: 32px;
				color: #202020;
			}

			.mainBox .addrBox .addrRow {
				padding: 20px 0;
				width: 100%;
				height: 48px;
				border-bottom: 1px solid #F0F0F0;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
			}

			.mainBox .addrBox .addrRow .rowName {
				width: 128px;
				font-weight: 400;
				font-size: 26px;
				color: #545458;
			}

			.mainBox .addrBox .addrRow .rowInput {
				width: calc(100% - 128px);
				height: 100%;
				position: relative;
			}

			.mainBox .addrBox .addrRow .rowInput>input {
				padding: 0 10px;
				width: calc(100% - 20px);
				height: 100%;
				border: none;
				font-weight: 400;
				font-size: 26px;
			}

			.mainBox .addrBox .addrRow .rowInput>input:focus,
			.mainBox .addrBox .addrRow .rowInput>input:active {
				border: none;
			}

			.mainBox .addrBox .addrRow .rowRight:after {
				content: "";
				position: absolute;
				width: 15px;
				height: 15px;
				right: 10px;
				top: 15px;
				border: 1px solid #888788;
				border-left-color: transparent;
				border-bottom-color: transparent;
				transform: rotate(45deg);
			}

			.mainBox .addrBox .addrBtn {
				margin: 30px 30px 0;
			}

			.mainBox .addrBox .addrBtn>button {
				width: 100%;
				padding: 0;
				margin: 0;
				border: none;
				background: transparent;
			}

			.mainBox .addrBox .addrBtn>button:active>img {
				opacity: 0.8;
			}

			.mainBox .stepBox {
				margin: 32px;
				padding: 30px 12px;
				width: calc(100% - 64px - 24px);
				background: #FFFFFF;
				border-radius: 24px;
				overflow: hidden;
				display: flex;
				flex-direction: column;
			}

			.mainBox .stepBox .stepTitle {
				margin-top: 36px;
				padding: 0 20px;
				font-weight: bold;
				font-size: 28px;
				color: #202020;
			}

			.mainBox .stepBox .stepTitle .stepText {
				margin-top: 24px;
				margin-bottom: 24px;
				padding: 0 20px;
				font-weight: 400;
				font-size: 24px;
				color: #545458;
				line-height: 44px;
			}


			.weui-picker-container,
			.weui-picker-overlay {
				width: 100%;
				height: 100%;
				background: rgba(0, 0, 0, 0.3);
			}

			.weui-picker-modal {
				height: 600px;
			}

			.toolbar .toolbar-inner {
				height: 80px;
			}

			.toolbar .title {
				font-size: 30px;
				line-height: 80px;
				margin: 0;
			}

			.toolbar .picker-button {
				font-size: 30px;
				font-weight: bold;
				line-height: 80px;
				padding: 0 30px;
				text-decoration: none;
			}

			.weui-picker-modal .picker-modal-inner {
				height: 520px;
			}

			.weui-picker-modal .picker-items {
				-webkit-mask-box-image: unset !important;
			}

			.city-picker .picker-items-col {
				max-width: 33%;
			}

			.weui-picker-modal .picker-item {
				height: 48px;
				text-align: center;
				font-size: 28px;
				line-height: 48px;
			}

			.weui-picker-modal .picker-item.picker-selected {
				transform: scale(1.2);
			}

			.weui-picker-modal .picker-center-highlight {
				height: 48px;
				line-height: 48px;
				margin-top: -24px;
			}
		</style>
	</head>
	<body>
		<div class="mainBox">
			<div class="topBox">
				<img src="/5G/static/top.jpg?3" width="100%" alt="5G高速大流量卡" />
				{if !empty($orders)}
				<div class="topTxt">{$orders.name}刚刚申领成功</div>
				{/if}
			</div>
			<div class="addrBox">
				<div class="addrTitle">收货地址</div>
				<div class="addrRow">
					<div class="rowName">收件人:</div>
					<div class="rowInput">
						<input id="username" type="text" placeholder="请输入收件人" autoComplete="false">
					</div>
				</div>
				<div class="addrRow">
					<div class="rowName">联系方式:</div>
					<div class="rowInput">
						<input id="phone" type="tel" placeholder="请输入联系方式" autoComplete="false">
					</div>
				</div>
				<div class="addrRow">
					<div class="rowName">所在地区:</div>
					<div class="rowInput">
						<input type='text' id='city-picker' class="" placeholder='请输入省市区' autoComplete="false" />
					</div>
				</div>
				<div class="addrRow">
					<div class="rowName">详细地址:</div>
					<div class="rowInput">
						<input id="address" type="text" placeholder="请输入详细地址" autoComplete="false">
					</div>
				</div>
				<div class="addrBtn">
					<button type="button" class="button" id="onApply">
						<img src="/5G/static/btn.png" width="100%" alt="立即申领" />
					</button>
				</div>
			</div>
			<div class="stepBox">
				<img src="/5G/static/step0.jpg" width="100%" alt="在线申领激活流程" />
				<div class="stepTitle">Q：号码如何预检？</div>
				<div class="stepText">1. 您在当前页面完成流量卡办理后，系统会发放一组号码给您，您需复制该号码，并识别下方二维码进入预检页面，按下图所示勾选1、2两处勾选按钮，然后点击“立即办理”按钮进入下一步页面。
				</div>
				<img src="/5G/static/step1.jpg" width="100%" alt="在线申领激活流程" />
				<div class="stepText">2. 您在下图页面填写/粘贴您上一步收到的号码，并按页面提示上传您的现场自拍照、身份证正反面照片、填写您的个人信息，点击“提交订单”按钮并支付完成办理。
				</div>
				<img src="/5G/static/step2.jpg" width="100%" alt="在线申领激活流程" />
				<div class="stepTitle">Q：如何实名激活？</div>
				<div class="stepText">
					在您收到流量卡后，可微信扫描卡套上的激活二维码或点击平台(10016)发送的手机卡开户成功短信中的链接，进入实名认证页面。根据页面提示填写iccid后7位数字和身份证后6位，点击“下一步”按钮，根据提示完成视频认证即可。
				</div>
				<img src="/5G/static/step3.jpg" width="100%" alt="在线申领激活流程" />
			</div>
		</div>
		<script src="/5G/city_picker_h5/js/jquery-1.10.2.js"></script>
		<!--<script type="text/javascript" src="/5G/city_picker_h5/js/jquery-weui.min.js"></script>-->
		<!--<script type="text/javascript" src="/5G/city_picker_h5/js/city-picker.min.js"></script>-->
		<script src="/static/service/js/layui/layui.all.js"></script>
		<script type="text/javascript">
			let username, phone, city, adderess, phone_number;
			$(document).ready(function() {
				// $("#city-picker").click(function() {
				// 	$("input").blur();
				// });
				// $("#city-picker").cityPicker({
				// 	title: "请选择所在地区",
				// 	onChange: function(picker, values, displayValues) {
				// 		console.log(values, displayValues);
				// 		city = displayValues;
				// 	}
				// });
				$("#onApply").click(function() {
					console.log('onApply');
					username = document.getElementById("username").value;
					phone = document.getElementById("phone").value;
					address = document.getElementById("address").value;
					city = document.getElementById("city-picker").value;
					onOrder();
				});
			});

			function onOrder() {
				console.log('onOrder');
				if (!username) {
				    layer.msg('请输入收件人!', {
						title: '温馨提示',
						time: 1500
					})
					return;
				}
				if (!phone) {
					layer.msg('请输入联系方式!', {
						title: '温馨提示',
						time: 1500
					})
					return;
				}
				const regex = /^1[3-9]\d{9}$/; // 中国大陆手机号码的正则表达式
				if (!regex.test(phone)) {
					layer.msg('请检查联系方式!', {
						title: '温馨提示',
						time: 1500
					})
					return;
				}
				if (!city) {
					layer.msg('请输入省市区!', {
						title: '温馨提示',
						time: 1500
					})
					return;
				}
				if (!address) {
				    layer.msg('请输入详细地址!', {
						title: '温馨提示',
						time: 1500
					})
					return;
				}
				$.ajax({
					url: "https://chat.wokahui.com/claim/index/put_order",
					type: "POST",
					data: {
						name: username,
						tel: phone,
						city: city,
						address: address,
						openid: "{:session('openid')}",
						old_iccid:'{$iccid}',
						account_no:'{$account_no}'
					},
					dataType: "json",
					timeout: 6000,
					beforeSend: function(xhr) {
						// 可选，发送请求前执行（如添加请求头、显示加载动画）
						console.log("准备发送请求...");
					},
					success: function(response) {
						// 必需，请求成功时执行（response 是服务器返回的数据）
						console.log("请求成功：", response);
						if (response.code == 0 ||  response.code==400) {
							phone_number = response.data.phone
							if (response.data.status == 1) {
								window.location.href = './complete?phone=' + response.data.phone
							} else {
							    window.location.href = './complete?phone=' + response.data.phone
								//onPaying(response.data.id)
							}

						}else {
							layer.msg(response.msg, {
								title: '温馨提示',
								time: 1500
							})
						}

					},
					error: function(xhr, status, error) {
						// 可选，请求失败时执行（如网络错误、服务器错误）
						console.log("请求失败：", status, error);
					},
					complete: function(xhr, status) {
						// 可选，请求完成后执行（无论成功或失败，如隐藏加载动画）
						console.log("请求结束");
					}
				});

			}

			function onPaying(id) {
				//调起支付
				$.post('./pay_order', {
					id
				}, function(res) {
					if (res.code == 0) {
						callpay(res.data);
					} else {
						layer.msg(res.msg, {
							title: '温馨提示',
							time: 1500
						})
					}
				})
			}

			function jsApiCall(data) {
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', {
						"appId": data.appId, //公众号名称，由商户传入
						"timeStamp": data.timeStamp, //时间戳，自1970年以来的秒数
						"nonceStr": data.nonceStr, //随机串
						"package": data.package,
						"signType": data.signType, //微信签名方式：
						"paySign": data.paySign //微信签名
					},
					function(res) {
						console.log(res);
						if (res.err_msg == "get_brand_wcpay_request:ok") {
							// 使用以上方式判断前端返回,微信团队郑重提示：
							//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
							window.location.href = './complete?phone=' + phone_number
						} else {}

					}
				);
			}

			function callpay(data) {
				if (typeof WeixinJSBridge == "undefined") {
					if (document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', jsApiCall(), false);
					} else if (document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', jsApiCall());
						document.attachEvent('onWeixinJSBridgeReady', jsApiCall());
					}
				} else {
					jsApiCall(data);
				}
			}
		</script>

	</body>
</html>